package com.sharelogindemo;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.sharelogindemo.wxapi.WeiChatShareUtil;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

public class ShareActivity extends BaseActivity {

    TextView mTextqqShareUrl, mTextqqSharePic, mTextqqShareMusic;
    TextView mTextqqZoneUrl, mTextqqZoneSharePic;
    TextView mTextWeiXinShareText, mTextWeiXinSharePic;
    TextView mTextWeiXinPengYouShareText,mTextWeiXinPengYouSharePic;
    QQShareUtil mShareUtil;
    WeiChatShareUtil mWeiChatShareUtil;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);
        mShareUtil = new QQShareUtil();
        mWeiChatShareUtil = new WeiChatShareUtil();
        mTextqqShareUrl = (TextView) findViewById(R.id.qq_share_url);
        mTextqqSharePic = (TextView) findViewById(R.id.qq_share_pic);
        mTextqqShareMusic = (TextView) findViewById(R.id.qq_share_music);

        mTextqqZoneUrl = (TextView) findViewById(R.id.qqzone_share_url);
        mTextqqZoneSharePic = (TextView) findViewById(R.id.qqzone_share_pic);

        mTextWeiXinShareText = (TextView) findViewById(R.id.weixin_share_text);
        mTextWeiXinSharePic = (TextView) findViewById(R.id.weixin_share_pic);
        mTextWeiXinPengYouShareText= (TextView) findViewById(R.id.weixin_PengYou_share_text);
        mTextWeiXinPengYouSharePic= (TextView) findViewById(R.id.weixin_PengYou_share_pic);

        mTextqqShareUrl.setOnClickListener(this);
        mTextqqSharePic.setOnClickListener(this);
        mTextqqShareMusic.setOnClickListener(this);
        mTextqqZoneUrl.setOnClickListener(this);
        mTextqqZoneSharePic.setOnClickListener(this);
        mTextWeiXinShareText.setOnClickListener(this);
        mTextWeiXinSharePic.setOnClickListener(this);
        mTextWeiXinPengYouShareText.setOnClickListener(this);
        mTextWeiXinPengYouSharePic.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
//            case R.id.weixin_share:
//                Platform weixin = ShareSDK.getPlatform (Wechat.NAME);
//                weixin.setPlatformActionListener(new PlatformActionListener() {
//                    @Override
//                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
//
//                    }
//
//                    @Override
//                    public void onError(Platform platform, int i, Throwable throwable) {
//
//                    }
//
//                    @Override
//                    public void onCancel(Platform platform, int i) {
//
//                    }
//                });
//                WeiChatShareUtil weixinUtil =new WeiChatShareUtil();
//                weixin.share(weixinUtil.shareWebPageUrlPassWeiXin("测试标题","测试内容","http://www.baidu.com","http://192.168.1.171/1.jpg"));
//
//                break;
            case R.id.weixin_share_text:
                mWeiChatShareUtil.shareTextPassWeiXin(Wechat.NAME, "测试文本", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("分享", throwable.toString());
                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            case R.id.weixin_share_pic:
                mWeiChatShareUtil.sharePicPassWeiXin(Wechat.NAME,"http://192.168.1.171/1.jpg", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                    }

                    @Override
                    public void onCancel(Platform platform, int i) {
                    }
                });
                break;
            case R.id.weixin_PengYou_share_text:
                mWeiChatShareUtil.shareTextPassWeiXin(WechatMoments.NAME, "测试文本", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("分享", throwable.toString());
                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            case R.id.weixin_PengYou_share_pic:
                mWeiChatShareUtil.sharePicPassWeiXin(WechatMoments.NAME, "http://192.168.1.171/1.jpg", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("分享", throwable.toString());
                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            //========================================================================================
            case R.id.qq_share_url:
                mShareUtil.shareUrlPassQQ("测试分享的标题", "http://www.baidu.com", "测试分享的文本", "http://192.168.1.171/1.jpg", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            case R.id.qq_share_pic:
                mShareUtil.sharePicturePassQQ("http://192.168.1.171/1.jpg", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            case R.id.qq_share_music:
                mShareUtil.shareMusicPassQQ("走在冬夜的冷风中", "歌词内容", "http://192.168.1.171/1.jpg", "http://192.168.1.171/test.mp3", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            case R.id.qqzone_share_url:
                mShareUtil.shareTextPassQQZone("测试分享的标题", "http://www.baidu.com", "测试分享的文本", "http://192.168.1.171/1.jpg", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;
            case R.id.qqzone_share_pic:
                mShareUtil.shareTalkPassQQZone("测试分享的内容", "http://192.168.1.171/1.jpg", new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {

                    }
                });
                break;

        }
    }
}
